package com.iot.system.domain.vo;

import com.iot.common.core.domain.entity.SysUser;
import com.iot.common.utils.DateUtils;

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.nio.file.attribute.FileOwnerAttributeView;
import java.util.Date;

/**
 * 文件属性
 */
public class FileVo {

    public FileVo(){}

    public FileVo(File file){
        this.setName(file.getName());
        this.setDirectory(file.isDirectory());
        this.setChildrenCount(file.isDirectory() ? file.list().length : 0);
        this.setSize(file.length());
        this.setPath(file.getPath());
        this.setUpdateTime(DateUtils.parseDateToStr(new Date(file.lastModified()), DateUtils.YYYY_MM_DD_HH_MM_SS));
        this.setHidden(file.isHidden());
        this.setReadonly(!file.canWrite());
        this.setRead(file.canRead());
        this.setWrite(file.canWrite());
        this.setExcute(file.canExecute());
    }

    private String name;// 名称
    private boolean directory;// 是否目录
    private boolean hidden;// 是否隐藏
    private boolean readonly;// 是否只读
    private boolean read;// 是否可读
    private boolean write;// 是否可写
    private boolean excute;// 是否可执行
    private long size;// 文件大小
    private String updateTime;// 更新时间
    private String path;// 路径
    private int childrenCount;// 文件数
    private String uploaderName;// 上传人
    private boolean deletePerm = false;// 是否有删除权限

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public boolean isDirectory() {
        return directory;
    }

    public void setDirectory(boolean directory) {
        this.directory = directory;
    }

    public boolean isHidden() {
        return hidden;
    }

    public void setHidden(boolean hidden) {
        this.hidden = hidden;
    }

    public boolean isReadonly() {
        return readonly;
    }

    public void setReadonly(boolean readonly) {
        this.readonly = readonly;
    }

    public boolean isRead() {
        return read;
    }

    public void setRead(boolean read) {
        this.read = read;
    }

    public boolean isWrite() {
        return write;
    }

    public void setWrite(boolean write) {
        this.write = write;
    }

    public boolean isExcute() {
        return excute;
    }

    public void setExcute(boolean excute) {
        this.excute = excute;
    }

    public long getSize() {
        return size;
    }

    public void setSize(long size) {
        this.size = size;
    }

    public String getUpdateTime() {
        return updateTime;
    }

    public void setUpdateTime(String updateTime) {
        this.updateTime = updateTime;
    }

    public String getPath() {
        return path;
    }

    public void setPath(String path) {
        this.path = path;
    }

    public int getChildrenCount() {
        return childrenCount;
    }

    public void setChildrenCount(int childrenCount) {
        this.childrenCount = childrenCount;
    }

    public String getUploaderName() {
        return uploaderName;
    }

    public void setUploaderName(String uploaderName) {
        this.uploaderName = uploaderName;
    }

    public boolean isDeletePerm() {
        return deletePerm;
    }

    public void setDeletePerm(boolean deletePerm) {
        this.deletePerm = deletePerm;
    }

    public static class FileProperties {
        private Long uploaderId;
        private String uploaderName;

        public Long getUploaderId() {
            return uploaderId;
        }

        public void setUploaderId(Long uploaderId) {
            this.uploaderId = uploaderId;
        }

        public String getUploaderName() {
            return uploaderName;
        }

        public void setUploaderName(String uploaderName) {
            this.uploaderName = uploaderName;
        }
    }
}
